package com.zeekr.orm.model.enums;

import lombok.Getter;
import org.apache.commons.lang3.ObjectUtils;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @author 吴文杰
 * @version 1.0
 * @since 2024/11/17 02:17
 */
@Getter
public enum UserRoleEnum {

  USER("用户", "user"),
  ADMIN("管理员", "admin"),
  BAN("被封号", "ban");

  private final String text;

  private final String value;

  UserRoleEnum(String text, String value) {
    this.text = text;
    this.value = value;
  }

  /**
   * 获取值列表
   *
   * @return
   */
  public static List<String> getValues() {
    return Arrays.stream(values()).map(item -> item.value).collect(Collectors.toList());
  }

  /**
   * 根据 value 获取枚举
   * @param value
   * @return
   */
  public static UserRoleEnum getEnumByValue(String value) {
    if (ObjectUtils.isEmpty(value)){
      return null;
    }
    for (UserRoleEnum item : UserRoleEnum.values()) {
      if (item.getValue().equals(value)){
        return item;
      }
    }
    return null;
  }
}
